What is mimer?
The 'mimer' npm package is a utility for determining the MIME type of a file based on its extension. It is useful for applications that need to handle files and their types, such as web servers, file upload handlers, and content management systems.
What are mimer's main functionalities?
Determine MIME type from file extension
This feature allows you to get the MIME type of a file by providing its filename or extension. In this example, 'example.txt' returns 'text/plain'.
const mimer = require('mimer');
const mimeType = mimer('example.txt');
console.log(mimeType); // Output: 'text/plain'
Default MIME type for unknown extensions
If the file extension is not recognized, 'mimer' returns a default MIME type, which is 'application/octet-stream' in this case.
const mimer = require('mimer');
const mimeType = mimer('example.unknown');
console.log(mimeType); // Output: 'application/octet-stream'
Other packages similar to mimer
mime
The 'mime' package is a comprehensive MIME type utility that can look up MIME types based on file extensions and vice versa. It also allows for custom MIME type definitions. Compared to 'mimer', 'mime' offers more extensive functionality and a larger database of MIME types.
mime-types
The 'mime-types' package provides a similar functionality to 'mimer' but with a more extensive list of MIME types and additional features like looking up extensions based on MIME types. It is more feature-rich and widely used in the community.
mime-db
The 'mime-db' package is a database of MIME types mapped to file extensions. It is used by other packages like 'mime' and 'mime-types' to provide their functionality. While 'mime-db' itself is not a utility, it serves as the backbone for MIME type lookups in other packages.
Mimer
A file extension to MIME type module. Uses mime-db data but with zero dependencies.
Getting started
npm install mimer
or npx mimer <file>
.
Module
const mimer = require('mimer');
mimer('.pdf');
mimer('pdf');
mimer('../readme.pdf');
mimer('pedefe');
Extension Map
const mimer = require('mimer');
const mimerMap = require('mimer/map');
mimerMap.get('pdf');
mimerMap.set('graphql', 'application/graphql');
mimer('content.graphql');
Safe mode
In case you want to avoid changes on original Map for safety.
const mimer = require('mimer/safe');
const mimerMap = require('mimer/map');
mimerMap.set('graphql', 'application/graphql');
mimer('content.graphql');
CLI
npm install -g mimer
mimer readme.pdf
or just
npx mimer readme.pdf
Contribute
Just create a new Github Codespace or:
$ git clone https://github.com/data-uri/mimer.git
$ cd mimer
$ npm i
$ npm test
License
MIT License
(c) Helder Santana